package engine.managers
{
	import com.lowke.assetManager.AssetManager;

	public class FileManager
	{
		private var _assetManager:AssetManager = new AssetManager();
		
		public static const CONTENT_PATH:String 	= "";//File.applicationDirectory.url;
		public static const ASSET_PATH:String		= "assets/";
		public static const DATA_PATH:String		= "data/";
		
		
		public function FileManager()
		{
			
		}
		
		/**
		 * Something is wrong with caching files. The cache appears always empty... Loading seems
		 * to work fine though.
		 */
		public function loadFiles(files:Array, handler:Function):void
		{
			for(var i:int = 0; i < files.length; i++)
			{
				var file:String = files[i];
				this._assetManager.cacheFile(CONTENT_PATH + file, false);
			}
			
			this._assetManager.whenDone(handler);
		}
		
		public function loadFile(file:String, handler:Function = null):void
		{
			this._assetManager.loadFile(CONTENT_PATH + file, handler);
		}
		
		public function getFile(file:String, clear:Boolean = true):*
		{
			var asset:* = this._assetManager.retrieve(CONTENT_PATH + file);
			
			if(clear) this._assetManager.forgetUrl(file);
			
			return asset;
		}
		
		public function clearCache(exceptions:* = null):void
		{
			if(!exceptions) 				this._assetManager.clear();
			else if(exceptions is String) 	this._assetManager.forgetUrl(exceptions);
			else if(exceptions is Array)
			{
				for(var i:int = 0; i < exceptions.length; i++)
					this._assetManager.forgetUrl(exceptions[i]);
			}
		}
	}
}